package UT02.db4o;

import java.util.ArrayList;

import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;

public class BaseDeDatos {

	final static String BD = "DB.yap";
	private ObjectContainer db;

	BaseDeDatos() {
		db = Db4oEmbedded.openFile(Db4oEmbedded.newConfiguration(), BD);
	}

	BaseDeDatos(String bd) {
		db = Db4oEmbedded.openFile(Db4oEmbedded.newConfiguration(), bd);
	}

	public void cerrarBD() {
		db.close();
	}

	public void guardar(Object o) {
		db.store(o);
	}

	public ArrayList<Object> consultar(Object o) {

		ArrayList<Object> resultado = new ArrayList<Object>();
		ObjectSet<Object> consulta = db.queryByExample(o);

		while (consulta.hasNext()) {
			resultado.add(consulta.next());

		}

		return resultado;

	}

}
